<template>
  <div>
    <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="200px">
      <el-form-item label="员工姓名" prop="empName">
        <el-input v-model="formData.empName" placeholder="请输入员工姓名" clearable :style="{width: '200px'}">
        </el-input>
      </el-form-item>
      <el-form-item label="电话号码" prop="empPhone">
        <el-input v-model="formData.empPhone" placeholder="请输入电话号码" :maxlength="11" show-word-limit clearable
          prefix-icon='el-icon-mobile' :style="{width: '200px'}"></el-input>
      </el-form-item>
      <el-form-item label="性别" prop="empGender">
        <el-select v-model="formData.empGender" placeholder="请输入性别" clearable :style="{width: '200px'}">
          <el-option v-for="(item, index) in empGenderOptions" :key="index" :label="item.label"
            :value="item.value" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="年龄" prop="empAge">
        <el-input v-model="formData.empAge" placeholder="请输入年龄" clearable :style="{width: '200px'}"></el-input>
      </el-form-item>
      <el-form-item label="家庭住址" prop="empHomeAddress">
        <el-input v-model="formData.empHomeAddress" placeholder="请输入家庭住址" clearable :style="{width: '200px'}">
        </el-input>
      </el-form-item>
      <el-form-item label="早中晚班" prop="empShift">
        <el-select v-model="formData.empShift" placeholder="请输入早中晚班" clearable :style="{width: '200px'}">
          <el-option v-for="(item, index) in empShiftOptions" :key="index" :label="item.label"
            :value="item.value" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item size="large">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import request from "@/utils/request";

export default {
  components: {},
  props: [],
  data() {
    return {
      formData: {
        empName: undefined,
        empPhone: '',
        empGender: undefined,
        empAge: undefined,
        empHomeAddress: undefined,
        empShift: undefined,
      },
      rules: {
        empName: [{
          required: true,
          message: '请输入员工姓名',
          trigger: 'blur'
        }],
        empPhone: [{
          required: true,
          message: '请输入电话号码',
          trigger: 'blur'
        }, {
          pattern: /^1(3|4|5|7|8|9)\d{9}$/,
          message: '手机号格式错误',
          trigger: 'blur'
        }],
        empGender: [{
          required: true,
          message: '请输入性别',
          trigger: 'change'
        }],
        empAge: [{
          required: true,
          message: '请输入年龄',
          trigger: 'blur'
        }],
        empHomeAddress: [{
          required: true,
          message: '请输入家庭住址',
          trigger: 'blur'
        }],
        empShift: [{
          required: true,
          message: '请输入早中晚班',
          trigger: 'change'
        }],
      },
      empGenderOptions: [{
        "label": "女",
        "value": 0
      }, {
        "label": "男",
        "value": 1
      }],
      empShiftOptions: [{
        "label": "早晚班",
        "value": 0
      }, {
        "label": "中班",
        "value": 1
      }, {
        "label": "无",
        "value": 2
      }],
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    submitForm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        addTable(this.formData).then(response => {
            this.$modal.msgSuccess("新增成功");
          });
        // TODO 提交表单
      })
    },
    resetForm() {
      this.$refs['elForm'].resetFields()
    },
  }
}
export function addTable(data) {
  return request({
    url: '/table/table',
    method: 'post',
    data: data
  })
}
</script>
<style>
</style>
